<template>
	<view class="wrap-partner-list safe-area flex column">
		<view class="wrap-screen flex align-center just-between">
			<picker mode="selector" :range="screenList" range-key="title" @change="onScreenChange">
				<view class="screen-info flex align-center">
					<view class="title f-28">{{ screen_title }}</view>

					<image class="arrow" :src="$staticImagePath('partner/arrow.png')" />
				</view>
			</picker>

			<view class="total f-28" v-if="total > 0">会员总数：{{ total }}</view>
		</view>

		<view class="wrap-list">
			<block v-for="(item, index) in list" :key="index">
				<view class="item flex align-center just-between">
					<image class="avatar" :src="$getImageURL(item.avatar)" />

					<view class="info flex column">
						<view class="name limit-num-line f-26">{{ item.nickname }}</view>

						<view class="mobile limit-num-line f-26">{{ item.hide_mobile }}</view>
						
						<view class="mobile limit-num-line f-26">{{ item.city }}</view>
						
						<view class="mobile limit-num-line f-26">{{ item.createtime_text }}</view>

						<view class="shop limit-num-line f-26" v-if="screen_id === '1'">{{ item.shopname }}</view>
					</view>

					<image class="phone" :src="$staticImagePath('partner/phone.png')" @click="$filters.onCallPhone(item.mobile)" />
				</view>
			</block>

			<wanl-empty v-if="list.length === 0" text="暂无数据" />
		</view>
	</view>
</template>

<script>
	import { QueryUserList } from "@/API/partner.js";
	export default {
		data() {
			return {
				isFirst: true,
				page: 1,
				total: 0,
				list: [],

				screenList: [
					{ title: "C端", id: "0" },
					{ title: "B端", id: "1" },
				],
				screen_id: "0",
				screen_title: "C端",
			};
		},
		methods: {
			/**
			 * 加载
			 */
			onInitData() {
				if (this.isFirst === false) {
					return;
				}
				this.isFirst = false;
				this.onRefresh();
			},
			/**
			 * 筛选
			 */
			onScreenChange(e) {
				const index = e.detail.value;
				const item = this.screenList[index];

				this.screen_title = item.title;
				this.screen_id = item.id;

				this.onRefresh();
			},
			/**
			 * 刷新
			 */
			onRefresh() {
				this.page = 1;
				this.getData();
			},
			/**
			 * 加载更多
			 */
			onLoadMore() {
				if (this.list.length < this.total) {
					this.page++;
					this.getData();
				}
			},
			/**
			 * 网络请求
			 */
			getData() {
				QueryUserList(this.page, this.screen_id).then((res) => {
					const list = res.data.data;
					this.total = res.data.total;
					if (this.page === 1) {
						this.list = list;
					} else {
						this.list = this.list.concat(list);
					}
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.wrap-partner-list {
		width: 100%;
		overflow: hidden;
		padding: 20rpx 25rpx;
		box-sizing: border-box;
		gap: 20rpx;

		.wrap-screen {
			width: 100%;
			overflow: hidden;

			.screen-info {
				height: 62rpx;
				background-color: white;
				border-radius: 10rpx;
				overflow: hidden;
				padding: 0rpx 25rpx;
				box-sizing: border-box;
				max-width: 100%;
				width: fit-content;
				gap: 30rpx;

				.title {
					color: #121212;
				}

				.arrow {
					width: 40rpx;
					height: 40rpx;
				}
			}
		}

		.wrap-list {
			width: 100%;
			overflow: hidden;

			.item {
				width: 100%;
				background-color: white;
				padding: 30rpx 20rpx;
				box-sizing: border-box;
				border-radius: 10rpx;
				overflow: hidden;
				margin-bottom: 20rpx;
				gap: 15rpx;

				&:last-child {
					margin-bottom: 0rpx;
				}

				.avatar {
					width: 100rpx;
					height: 100rpx;
					border-radius: 10rpx;
					overflow: hidden;
				}

				.info {
					flex: 1;
					overflow: hidden;
					gap: 15rpx;
					--limit-num: 1;

					.name {
						color: #865b2a;
					}

					.mobile {
						color: #999;
					}

					.shop {
						color: #999;
					}
				}

				.phone {
					width: 40rpx;
					height: 40rpx;
				}
			}
		}
	}
</style>
